def concat(p, it):
	if type(it) == list:
		return [p] + it
	return [p, it]

def itere(deg, n):
	if deg == 0:
		return []
	if deg == 1:
		return range(n)
	else:
		return [concat(p, it) for it in itere(deg-1, n) for p in xrange(n)]

n = 4
nbBoucleImbre = 3
print itere(nbBoucleImbre, n)
print "====="
res = []
for x in xrange(n):
	for y in xrange(n):
		for z in xrange(n):
			res.append([x,y,z])

print res

print "===="
from itertools import product

def generer(r, n):
    return list(product(r, repeat=n))

print generer(range(n), nbBoucleImbre)
